import apiClient from './config'
import type { 
  DashboardStats,
  AccessTrend,
  UserDistribution,
  RecentActivity,
  SystemStatus,
  ApiResponse 
} from './types'

export const dashboardApi = {
  // 获取仪表盘统计数据
  getStats: (): Promise<ApiResponse<DashboardStats>> => {
    return apiClient.get('/dashboard/stats')
  },

  // 获取访问趋势数据
  getAccessTrends: (days: number = 7): Promise<ApiResponse<AccessTrend[]>> => {
    return apiClient.get('/dashboard/access-trends', { 
      params: { days } 
    })
  },

  // 获取用户分布数据
  getUserDistribution: (): Promise<ApiResponse<UserDistribution[]>> => {
    return apiClient.get('/dashboard/user-distribution')
  },

  // 获取最近活动
  getRecentActivities: (limit: number = 10): Promise<ApiResponse<RecentActivity[]>> => {
    return apiClient.get('/dashboard/recent-activities', { 
      params: { limit } 
    })
  },

  // 获取系统状态
  getSystemStatus: (): Promise<ApiResponse<SystemStatus>> => {
    return apiClient.get('/dashboard/system-status')
  },

  // 获取在线用户数
  getOnlineUsers: (): Promise<ApiResponse<{ count: number; users: any[] }>> => {
    return apiClient.get('/dashboard/online-users')
  },

  // 获取今日新增数据
  getTodayStats: (): Promise<ApiResponse<{
    newUsers: number
    newRoles: number
    newPermissions: number
    loginCount: number
  }>> => {
    return apiClient.get('/dashboard/today-stats')
  },

  // 获取热门页面访问统计
  getPopularPages: (limit: number = 10): Promise<ApiResponse<{
    path: string
    count: number
    title: string
  }[]>> => {
    return apiClient.get('/dashboard/popular-pages', { 
      params: { limit } 
    })
  },

  // 获取错误日志统计
  getErrorStats: (days: number = 7): Promise<ApiResponse<{
    date: string
    count: number
    level: string
  }[]>> => {
    return apiClient.get('/dashboard/error-stats', { 
      params: { days } 
    })
  },

  // 获取性能指标
  getPerformanceMetrics: (): Promise<ApiResponse<{
    responseTime: number
    throughput: number
    errorRate: number
    uptime: number
  }>> => {
    return apiClient.get('/dashboard/performance')
  }
}